<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php';?>
<?php
$noms='';
$refs='';
$infs='';
if(isset($_POST['noms'])&&isset($_POST['refs'])&&isset($_POST['infc'])) 
{      
		$noms=$db->quote($_POST['noms']);
		$refs=$db->quote($_POST['refs']);
		$infc=$db->quote($_POST['infc']);
		if(isset($_GET['id'])){
			$id=$db->quote($_GET['id']);
			$db->query("update societe set societeNom=$noms,societeRef=$refs,societeDetails=$infc where societeId=$id");
			header('Location: /prescription/company.php');
			die();
		}
		else
		{
			$db->query("insert into societe set societeNom=$noms,societeRef=$refs,societeDetails=$infc");
			header('Location: /prescription/company.php');
			die();
		}
}

if(isset($_GET['id'])){
		$id=$db->quote($_GET['id']);
		$select=$db->query("select * from societe where societeId=$id");
	    $_POST=$select->fetch();
		$noms=$db->quote($_POST['societeNom']);
		$refs=$db->quote($_POST['societeRef']);
		$infs=$db->quote($_POST['societeDetails']);
	}
?>
<form class="form-horizontal" action="#" method="post">
<br>
<h3><span class="titre">&nbsp;&nbsp;Détails de la société</span></h3>
<br>
   <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Nom de la société:</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="noms" value="<?php echo str_replace("'","",$noms) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Réference de la société :</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="refs" value="<?php echo str_replace("'","",$refs) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-4 control-label">Informations complémentaires :</label>
    <div class="col-sm-5">
     <input type="text" class="form-control"  name="infc" value="<?php echo str_replace("'","",$infs) ; ?>">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-4 col-sm-10">
      <button  type="submit" class="btn btn-success">valider</button>
	  <a href="company.php" class="btn btn-default">annuler</a>
    </div>
  </div>
</form>
<?php include 'partials/footer.php'; ?>
